<template>
	<view>
		<u-tabs
			:list="tabsList" 
			active-color="#849ee3" 
			inactive-color="#606266" 
			:is-scroll="false" 
			:current="current"
			@change="tabChange">
		</u-tabs>
		<view class="container u-relative" style="top: 78rpx;">
			<template v-if="dataList.length > 0">
				<block v-for="(item,index) in dataList" :key="index">
					<view class="u-padding-20 white-bg z-b-r u-flex u-margin-bottom-20">
						<view>
							<view>
								<text>项目名称：{{ item.project_name }}</text>
							</view>
							<view>
								<text>联系电话：{{ item.phone }}</text>
							</view>
							<view>
								<text>项目地址：{{ item.project_address }}</text>
							</view>
							<view>
								<text>起止日期：{{ item.start_date }}—{{ item.end_date }}</text>
							</view>
							<view>
								<text>其他条件：{{ item.others }}</text>
							</view>
						</view>
						<view class="u-margin-left-20 u-margin-right-20 u-flex-1 u-flex" v-if="item.status === 1">
							<view><u-tag size="mini" @click="updateHandle(item,'update',index)" text="结束" type="warning"/></view>
							<view class="u-padding-20">|</view>
							<view><u-tag size="mini" @click="updateHandle(item,'delete',index)" text="删除" type="error"/></view>
						</view>
						<view class="u-margin-left-20 u-margin-right-20 u-flex-1 u-flex u-row-center" v-if="item.status === 0">
							<view><u-tag size="mini" @click="updateHandle(item,'delete',index)" text="删除" type="error"/></view>
						</view>
					</view>
				</block>
			</template>
			<template v-else>
				<empty-data tipText="暂无招聘信息"></empty-data>
			</template>
		</view>
		<!-- 消息提示 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {mapState} from "vuex";
	export default {
		data() {
			return {
				tabsList: [{
					name: '正在招聘',
					id:1
				}, {
					name: '已结束',
					id:0
				}],
				current: 0,
				dataList:[]
			}
		},
		computed:{
			...mapState({
				token:"token",
				userID:"userID"
			})
		},
		onLoad() {
			this.initDataList(1)
		},
		methods: {
			tabChange(index){
				this.current = index;
				this.initDataList(this.tabsList[index].id)
			},
			async updateHandle(item,type,index){
				let {token,userID} = this;
				this.$loading("正在操作")
				let res = await this.$network({
					api:"main",
					data:{
						action:"recruitment/pmRecruitmentAdmin",
						data:{
							token,
							type,
							data:{
								_id:item._id
							}
						}
					}
				})
				uni.hideLoading();
				if(res.status === 0){
					this.$refs.uToast.show({
						title: '操作成功',
						type: 'success'
					})
					this.dataList.splice(index,1);
				}
			},
			async initDataList(status){
				let {token,userID} = this;
				this.$loading("正在加载")
				let res = await this.$network({
					api:"main",
					data:{
						action:"recruitment/pmRecruitmentAdmin",
						data:{
							token,
							type:'get', //类型：获取数据
							data:{
								userID,
								status //0：过期，1：未过期
							}
						}
					}
				})
				uni.hideLoading();
				if(res.status === 0){
					this.dataList = res.data;
				} else if(res.status === 1){
					this.dataList = [];
				}
			}
		}
	}
</script>
